package com.eshop.service.impl.mongodb.manager;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.eshop.dao.mongodb.manager.ManagerDao;
import com.eshop.frameworks.core.dao.DAO;
import com.eshop.frameworks.core.entity.PageEntity;
import com.eshop.frameworks.core.service.impl.AbstractService;
import com.eshop.model.mongodb.manager.Manager;
import com.eshop.service.mongodb.manager.ManagerService;

@Service("managerService")
public class ManagerServiceImpl extends AbstractService<Manager, String> implements ManagerService {
	@Autowired
	private ManagerDao managerDao;

	@Override
	public DAO<Manager, String> getDao() {
		return managerDao;
	}

	@Override
	public Manager getUserByNameAndPwd(String name, String pwd) {
		return getDao().findOne(new Query(Criteria.where("loginName").is(name).and("loginPwd").is(pwd).and("status").ne(Manager.DELETE_STATUS)), Manager.class);
	}

	@Override
	public List<Manager> getManagerPage(Manager manager, PageEntity page) {
		Query query = new Query(Criteria.where("status").ne(Manager.DELETE_STATUS));
		query.with(new Sort(Direction.DESC,"createTime"));
		query.skip(page.getStartRow()).limit(page.getPageSize());
		return getDao().findList(query, Manager.class);
	}

}
